<?php
/**
 * Created by PhpStorm.
 * User: thanatos
 * Date: 2017/11/20
 * Time: 下午4:06
 */

namespace common\actions;


use common\helpers\AjaxHelper;
use Yii;
use common\models\SmsForm;
use yii\base\Action;

class SmsAction extends Action{
    
    public function run()
    {
        $model = new SmsForm;
        $response = new AjaxHelper;
        
        $model->attributes = Yii::$app->request->getBodyParams();
        $model->type = SmsForm::TYPE_REGISTER;
        
        if( $code = $model->send() ){
            $response->data = YII_ENV_DEV ? ['code' => $code] : '发送成功';
        }else{
            $response->msg = $model->getOneErrors() ?: '发送失败';
        }
        
        return $response;
        
    }
    
}